package com.example.lib_core.network;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;


public class RetrofitManager {

    private static RetrofitManager retrofitManager;

    public static RetrofitManager getInstance() {
        if (retrofitManager==null){
            retrofitManager=new RetrofitManager();
        }
        return retrofitManager;
    }
    private Retrofit retrofit;

    public Retrofit getRetrofit() {
        if (retrofit==null){
            HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
            interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
            OkHttpClient.Builder okbuilder = new OkHttpClient.Builder();
            okbuilder.addInterceptor(interceptor);
            okbuilder.readTimeout(1, TimeUnit.MINUTES);
            okbuilder.connectTimeout(1,TimeUnit.MINUTES);

            Retrofit.Builder builder = new Retrofit.Builder();
//            builder.baseUrl(Api.BASE_URL);
            builder.baseUrl(Api.HOME_URL);
            builder.addCallAdapterFactory(RxJava2CallAdapterFactory.create());
            builder.addConverterFactory(GsonConverterFactory.create());
            retrofit=builder.build();

        }
        return retrofit;
    }
}
